package fudan.se.project.controller.account;

import fudan.se.project.controller.request.LoginRequest;
import fudan.se.project.controller.request.RegisterRequest;
import fudan.se.project.service.advanced.account.AccountService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Gao Longchao
 */
@Slf4j
@RestController
public class AccountController {

    private AccountService accountService;


    @Autowired
    public AccountController(AccountService accountService) {
        this.accountService = accountService;
    }


    @PostMapping("/register")
    public ResponseEntity<?> register(@Validated @RequestBody RegisterRequest request) {

        log.debug("register: " + request.toString());

        return accountService.register(request);
    }

    @PostMapping("/login")
    public ResponseEntity<?> login(@Validated @RequestBody LoginRequest request) {
        log.debug("login: " + request.toString());
        return accountService.login(request);
    }

    @PostMapping("/update")
    public ResponseEntity<?> update() {
        log.debug("update");
        return accountService.update();
    }

}



